package com.wd.live.view;

import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.GridLayoutManager;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.wd.live.R;
import com.wd.live.base.BaseFragment;
import com.wd.live.base.BaseViewModel;
import com.wd.live.bean.ContellationBeen;
import com.wd.live.bean.ModifyConstellationBeen;
import com.wd.live.databinding.ConstellationFragmentBinding;
import com.wd.live.view.activity.MainActivity;
import com.wd.live.view.adpater.ConstellCelectAdapter;

import com.wd.live.viewmodel.MainViewModel;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;

public class ConstellationFragment extends BaseFragment<MainViewModel, ConstellationFragmentBinding> {


    @Override
    protected void initData() {
        databind.jump.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MainActivity.class);
                startActivity(intent);
            }
        });
        viewmodel.getCollData().observe(getActivity(), new Observer<ContellationBeen>() {
            @Override
            public void onChanged(ContellationBeen contellationBeen) {
                ConstellCelectAdapter constellCelectAdapter = new ConstellCelectAdapter(getActivity(), R.layout.constellation_item, contellationBeen.getResult());
                databind.costellationrec.setLayoutManager(new GridLayoutManager(getContext(),3));
                databind.costellationrec.setAdapter(constellCelectAdapter);
                constellCelectAdapter.setCallBack(new ConstellCelectAdapter.CallBack() {
                    @Override
                    public void Call(ContellationBeen.ResultBean resultBean, int position) {
                        viewmodel.getModifyConData(resultBean.getConstellationId())
                                .observe(getActivity(), new Observer<ModifyConstellationBeen>() {
                                    @Override
                                    public void onChanged(ModifyConstellationBeen modifyConstellationBeen) {
                                        Toast.makeText(getActivity(), modifyConstellationBeen.getMessage(), Toast.LENGTH_SHORT).show();
                                    }
                                });
                    }
                });
            }
        });


    }

    @Override
    protected int initLayout() {
        return R.layout.constellation_fragment;
    }

    @Override
    public void onChanged(Object o) {

    }
}